/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "PRODUCT")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
    @NamedQuery(name = "Product.findByIdProduct", query = "SELECT p FROM Product p WHERE p.productPK.idProduct = :idProduct"),
    @NamedQuery(name = "Product.findByIdBranchenterprise", query = "SELECT p FROM Product p WHERE p.productPK.idBranchenterprise = :idBranchenterprise"),
    @NamedQuery(name = "Product.findByIdEnterprise", query = "SELECT p FROM Product p WHERE p.productPK.idEnterprise = :idEnterprise"),
    @NamedQuery(name = "Product.findByName", query = "SELECT p FROM Product p WHERE p.name = :name"),
    @NamedQuery(name = "Product.findByDetail", query = "SELECT p FROM Product p WHERE p.detail = :detail"),
    @NamedQuery(name = "Product.findByPrice", query = "SELECT p FROM Product p WHERE p.price = :price"),
    @NamedQuery(name = "Product.findByCommission", query = "SELECT p FROM Product p WHERE p.commission = :commission"),
    @NamedQuery(name = "Product.findByCode", query = "SELECT p FROM Product p WHERE p.code = :code")})
public class Product implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProductPK productPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 180)
    @Column(name = "NAME")
    private String name;
    @Size(max = 180)
    @Column(name = "DETAIL")
    private String detail;
    @Basic(optional = false)
    @NotNull
    @Column(name = "PRICE")
    private BigInteger price;
    @Basic(optional = false)
    @NotNull
    @Column(name = "COMMISSION")
    private BigInteger commission;
    @Column(name = "CODE")
    private BigInteger code;
    @Lob
    @Column(name = "PHOTO")
    private Serializable photo;
    @JoinTable(name = "SOLUCIONES", joinColumns = {
        @JoinColumn(name = "PRODUCT_ID_PRODUCT", referencedColumnName = "ID_PRODUCT"),
        @JoinColumn(name = "PRODUCT_ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE"),
        @JoinColumn(name = "PRODUCT_ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE")}, inverseJoinColumns = {
        @JoinColumn(name = "SERVICE_ID_SERVICE", referencedColumnName = "ID_SERVICE"),
        @JoinColumn(name = "SERVICE_ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE"),
        @JoinColumn(name = "SERVICE_ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE")})
    @ManyToMany(fetch = FetchType.LAZY)
    private List<Service> serviceList;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "product", fetch = FetchType.LAZY)
    private ProductPreference productPreference;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "product", fetch = FetchType.LAZY)
    private List<Item> itemList;
    @JoinColumns({
        @JoinColumn(name = "ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE", insertable = false, updatable = false),
        @JoinColumn(name = "ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE", insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private BranchEnterprise branchEnterprise;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "product", fetch = FetchType.LAZY)
    private List<Consolidated> consolidatedList;

    public Product() {
    }

    public Product(ProductPK productPK) {
        this.productPK = productPK;
    }

    public Product(ProductPK productPK, String name, BigInteger price, BigInteger commission) {
        this.productPK = productPK;
        this.name = name;
        this.price = price;
        this.commission = commission;
    }

    public Product(BigInteger idProduct, BigInteger idBranchenterprise, BigInteger idEnterprise) {
        this.productPK = new ProductPK(idProduct, idBranchenterprise, idEnterprise);
    }

    public ProductPK getProductPK() {
        return productPK;
    }

    public void setProductPK(ProductPK productPK) {
        this.productPK = productPK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public BigInteger getPrice() {
        return price;
    }

    public void setPrice(BigInteger price) {
        this.price = price;
    }

    public BigInteger getCommission() {
        return commission;
    }

    public void setCommission(BigInteger commission) {
        this.commission = commission;
    }

    public BigInteger getCode() {
        return code;
    }

    public void setCode(BigInteger code) {
        this.code = code;
    }

    public Serializable getPhoto() {
        return photo;
    }

    public void setPhoto(Serializable photo) {
        this.photo = photo;
    }

    @XmlTransient
    public List<Service> getServiceList() {
        return serviceList;
    }

    public void setServiceList(List<Service> serviceList) {
        this.serviceList = serviceList;
    }

    public ProductPreference getProductPreference() {
        return productPreference;
    }

    public void setProductPreference(ProductPreference productPreference) {
        this.productPreference = productPreference;
    }

    @XmlTransient
    public List<Item> getItemList() {
        return itemList;
    }

    public void setItemList(List<Item> itemList) {
        this.itemList = itemList;
    }

    public BranchEnterprise getBranchEnterprise() {
        return branchEnterprise;
    }

    public void setBranchEnterprise(BranchEnterprise branchEnterprise) {
        this.branchEnterprise = branchEnterprise;
    }

    @XmlTransient
    public List<Consolidated> getConsolidatedList() {
        return consolidatedList;
    }

    public void setConsolidatedList(List<Consolidated> consolidatedList) {
        this.consolidatedList = consolidatedList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productPK != null ? productPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.productPK == null && other.productPK != null) || (this.productPK != null && !this.productPK.equals(other.productPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Product[ productPK=" + productPK + " ]";
    }
    
}
